#ifndef _ICFPC2008_CONTROLLER_H_
#define _ICFPC2008_CONTROLLER_H_

#include "message.h"
#include "point.h"
#include "position.h"

class Controller
{
private:
	static const double delta = .01;
	char resp[4];
	double minX, maxX, minY, maxY; //map borders
	unsigned long maxTime;	//time limit
	double minSensor, maxSensor;
	double maxLinearSpeed, maxTurnSpeed, maxHardTurnSpeed; //maxumum speeds
	
	double speed; //last values
	Position last;
	char speedState, turnState; //last remembered

	double exp_speed; //expected
	Position expected;
	char exp_speedState, exp_turnState; //expected
	
	unsigned long timestamp;
	

	Position sweetPosition;	

	std::list<StaticObject*> map;
	std::list<Martian*> martians;
	Home* home;
protected:
	double distancePoints(Point a, Point b);
	double distanceLinePoint(Position p, Point b);
	Point crashPoint(Position a, Position b);
	double getAngle(Point a, Point b);
	StaticObject* isWayClear(Position p, double dist);
	bool isPointAhead(Position p, Point pt);
	void calculate();
	void goSweetPosition(const Message* msg);
	bool turnRightDirection(char ch, bool turnLeft);
public:
	Controller();
	char* makeDecision(const Message* msg);
	char* init(const Message* msg);
	char* notify(const Message* msg);
	char* cleanup(const Message* msg);
	~Controller();
};

#endif
